package org.yihang.util;

public class MiddleProperty {

    private String ownColumn;
    private String ownVar;

    private String oppositeColumn;
    private String oppositeVar;

    private String table;
    private String title;
    private String op_s; // 对方类的简名,例如:Role
    private String op_ss;// 对方类的变量名,例如:role

    public MiddleProperty(String table, Class oppositeClass, String title, String ownColumn, String oppositeColumn) {
        this.table = table;
        String s = oppositeClass.getSimpleName();
        this.op_s = s;
        this.op_ss = Character.toLowerCase(s.charAt(0)) + s.substring(1);
        this.title = title;
        this.ownColumn = ownColumn;
        this.oppositeColumn = oppositeColumn;
        this.ownVar = underscoreToCamel(ownColumn);
        this.oppositeVar = underscoreToCamel(oppositeColumn);
    }

    public String getOwnColumn() {
        return ownColumn;
    }

    public String getOwnVar() {
        return ownVar;
    }

    public String getOppositeColumn() {
        return oppositeColumn;
    }

    public String getOppositeVar() {
        return oppositeVar;
    }

    public String getTable() {
        return table;
    }

    public String getTitle() {
        return title;
    }

    public String getOp_s() {
        return op_s;
    }

    public String getOp_ss() {
        return op_ss;
    }

    public static String underscoreToCamel(String column){
        StringBuilder sb = new StringBuilder(column.length());
        String[] words = column.split("_");
        int i = 1;
        for(String w :words) {
            if(i==1) {
                sb.append(Character.toLowerCase(w.charAt(0)));
            } else {
                sb.append(Character.toUpperCase(w.charAt(0)));
            }
            sb.append(w.substring(1));
            i++;
        }
        return sb.toString();
    }
}
